---
category: Date Time
created: '2020-04-19'
title: 'Extract year, month, day, hour, minute, second and millisecond from a date'
updated: '2021-10-13'
---

**JavaScript version**

```js extract.js
// `date` is a `Date` object
const extract = (date) =>
    date
        .toISOString()
        .split(/[^0-9]/)
        .slice(0, -1);

// `extract` is an array of [year, month, day, hour, minute, second, millisecond]
```

**TypeScript version**

```ts extract.ts
const extract = (date: Date): string[] =>
    date
        .toISOString()
        .split(/[^0-9]/)
        .slice(0, -1);
```
